﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace PrototipoMVC3IU.Controllers
{
    public class InicioController : Controller
    {
        //
        // GET: /Inicio/

        public ActionResult Inicio()
        {
            return View();
        }

        public ActionResult AcercaDe() 
        {
            return View();
        }

        public ActionResult AccesoSinCredencial() 
        {
            return View();
        }

        [HttpPost]
        public ActionResult AccesoSinCredencial(FormCollection Collection) 
        {
            string ButtonClick = Collection["ButtonClick"].ToString();
            switch (ButtonClick) 
            {
                case "Volver":
                    return RedirectToAction("Inicio", "Inicio");
                default:
                    return View();
            }
        }

        public ActionResult Autenticacion() 
        {
            return View();
        }

        [HttpPost]
        public ActionResult Autenticacion(FormCollection Collection)
        {
            string Usuario = Collection["Usuario"].ToString();
            string Clave = Collection["Clave"].ToString();
            string ButtonClick = Collection["ButtonClick"].ToString();
            switch (ButtonClick)
            {
                case "Acceder":
                    if (Usuario == "admin" && Clave == "123456")
                    {
                        Session["id"] = 1;
                        return RedirectToAction("Inicio", "Inicio");
                    }
                    return RedirectToAction("ErrorCredencial");
                case "Volver":
                    return RedirectToAction("Inicio", "Inicio");
                default:
                    return View();
            }
        }

        public ActionResult Desloguear() 
        {
            Session.RemoveAll();
            return RedirectToAction("Inicio", "Inicio");
        }

        public ActionResult ErrorCredencial() 
        {
            return View();
        }

        [HttpPost]
        public ActionResult ErrorCredencial(FormCollection Collection)
        {
            string ButtonClick = Collection["ButtonClick"].ToString();
            switch (ButtonClick) 
            {
                case "Volver":
                    return RedirectToAction("Autenticacion", "Inicio");
            }
            return View();
        }
    }
}
